package com.IMI.DatabaseActivity;

import java.io.InputStream;

import org.json.JSONArray;
import org.json.JSONObject;

import android.content.Context;
import android.util.Log;

public class getData {

	private int i=0;
	public String[] stock_name = new String[100];
	public String[] stock_id = new String[100];
	public String[] stock_price = new String[100];
	public int ctr=0;
	  void examineJSONFile(Context context)
	    {
	    	try
	    	{
	    		String x = "";
	    		//System.out.println("before context");
	    		InputStream is = context.getResources().openRawResource(R.raw.sample);
	    		//System.out.println("after context");
	    		byte [] buffer = new byte[is.available()];
	    		//while (is.read(buffer) != '[');
	    		//byte [] buffer1 = new byte[is.available()];
	    		while (is.read(buffer) != -1);
	    		String jsontext = new String(buffer);
	    		JSONArray entries = new JSONArray(jsontext);
	    		
	    		x = "JSON parsed.\nThere are [" + entries.length() + "]\n\n";
	    		
	    		ctr=entries.length();
	    		//System.out.println("here ctr is" + ctr);
	    		for (i=0;i<entries.length();i++)
	    		{
	    			JSONObject post = entries.getJSONObject(i);
	    			
	    			//String here = post.getString("created_at");
	    			stock_name[i] = post.getString("NAME").toString();
	    			stock_id[i] = post.getString("SID").toString();
	    			stock_price[i] = post.getString("SVAL").toString();
	    			Log.d("Test...while taking data from xml file", stock_id[i]);
	    		  	
	    		}
	    	}
	    	catch (Exception je)
	    	{
	    	}
	    }
}
